import { request } from '@umijs/max';

// 获取商品列表
export async function getGoodsList(params: API.GoodsAdminParams) {
  return request<API.QueryResult>('/goods/list', {
    method: 'GET',
    params,
    headers: {
      'X-Requested-With': 'XMLHttpRequest',
      token: localStorage.getItem('token') || '',
    },
  });
}

// 上架商品
export async function solveGoods(ids: any[]) {
  return request('/goods/status/0', {
    method: 'put',
    data: {
      ids,
    },
    headers: {
      token: localStorage.getItem('token') || '',
    },
  });
}

// 上架商品
export async function forbidGoods(ids: any[]) {
  return request('/goods/status/1', {
    method: 'put',
    data: {
      ids,
    },
    headers: {
      token: localStorage.getItem('token') || '',
    },
  });
}

// 新增商品
export async function addGoods(data: any) {
  return request('/goods', {
    method: 'post',
    data,
    headers: {
      token: localStorage.getItem('token') || '',
    },
  });
}

// 修改商品
export async function editGoods(data: any) {
  return request('/goods', {
    method: 'put',
    data,
    headers: {
      token: localStorage.getItem('token') || '',
    },
  });
}
